{
 "cells": [
  {
   "cell_type": "markdown",
   "source": [
    "# Inference SRCNN\n",
    "This tutorial shows how to create model instance and load pretrained weights.\n",
    "- Construct model\n",
    "- Load weights\n",
    "- Make inference on an image"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%% md\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "outputs": [
    {
     "name": "stderr",
     "text": [
      "2020-02-11 22:41:04,884 INFO: Total params: 57281\n"
     ],
     "output_type": "stream"
    },
    {
     "name": "stdout",
     "text": [
      "(1, 1, 768, 768)\n"
     ],
     "output_type": "stream"
    }
   ],
   "source": [
    "import torchvision\n",
    "from PIL import Image\n",
    "\n",
    "from VSR.Model import get_model\n",
    "\n",
    "srcnn_builder = get_model('srcnn')\n",
    "srcnn = srcnn_builder(scale=3, channel=1)\n",
    "srcnn.display()\n",
    "try:\n",
    "    srcnn.load(\"srcnn.pth\")\n",
    "except FileNotFoundError:\n",
    "    pass\n",
    "\n",
    "img = Image.open(\"../../Tests/data/set5_x2/img_001_SRF_2_LR.png\")\n",
    "F = torchvision.transforms.Compose([torchvision.transforms.Grayscale(),\n",
    "                                    torchvision.transforms.ToTensor()])\n",
    "img = F(img)\n",
    "img = img.unsqueeze(0)\n",
    "ret, _ = srcnn.eval([img])\n",
    "print(ret[0].shape)"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n",
     "is_executing": false
    }
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "To list all supported models"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "outputs": [
    {
     "name": "stdout",
     "text": [
      "dict_keys(['espcn', 'srcnn', 'vdsr', 'dncnn', 'drcn', 'drrn', 'ffdnet', 'edsr', 'carn', 'dbpn', 'rcan', 'srfeat', 'esrgan', 'msrn', 'crdn', 'mldn', 'drn', 'sofvsr', 'vespcn', 'frvsr', 'qprn', 'ufvsr', 'yovsr', 'tecogan', 'spmc', 'rbpn', 'didn', 'dhdn', 'grdn', 'resunet', 'edrn', 'frn', 'ran'])\n"
     ],
     "output_type": "stream"
    }
   ],
   "source": [
    "from VSR.Model import list_supported_models\n",
    "\n",
    "print(list_supported_models())"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n",
     "is_executing": false
    }
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "- [x] Next: [Building data pipeline with DataLoader](./2.%20Building%20data%20pipeline%20with%20DataLoader.ipynb)"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%% md\n"
    }
   }
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  },
  "pycharm": {
   "stem_cell": {
    "cell_type": "raw",
    "source": [],
    "metadata": {
     "collapsed": false
    }
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}